package com.ihr360.binlog.listener;


import com.ihr360.binlog.component.BinlogReceiverStarter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationListener;
import org.springframework.context.event.ContextClosedEvent;
import org.springframework.stereotype.Component;

import java.util.logging.Logger;


/**1
 * Created by davidwei on 17-8-2.
 */
@Component
public class ApplicationStopListener implements ApplicationListener<ContextClosedEvent> {
    Logger logger = Logger.getLogger(ApplicationStopListener.class.getName());

    @Autowired
    private BinlogReceiverStarter receiverStarter;

    @Override
    public void onApplicationEvent(ContextClosedEvent contextClosedEvent) {
        if(contextClosedEvent.getApplicationContext().getParent() == null) {
           receiverStarter.stopAll();
        }
    }
}
